<template>
  <div class="profile-container">
    <el-row :gutter="24" class="profile-content">
      <!-- 左侧个人信息卡片 -->
      <el-col :span="24" :md="8">
        <el-card class="info-card avatar-card">
          <div class="avatar-section">
            <div class="avatar-wrapper">
              <div class="avatar-container">
                <img 
                  v-if="profileForm.avatar" 
                  :src="profileForm.avatar" 
                  class="avatar" 
                  alt="用户头像"
                />
                <div v-else class="avatar-placeholder">
                  <el-icon class="avatar-icon"><User /></el-icon>
                </div>
              </div>
              <h3 class="user-nickname">{{ profileForm.nickname || '未设置昵称' }}</h3>
              <p class="user-username">@{{ profileForm.username }}</p>
            </div>
            
            <el-upload
              ref="uploader"
              action="#"
              :auto-upload="false"
              :show-file-list="false"
              :on-change="handleAvatarChange"
              :disabled="!isEditing"
              v-if="isEditing"
              class="avatar-upload"
            >
              <el-button 
                type="primary" 
                class="upload-btn"
                :icon="Plus"
                @click="$refs.uploader.$el.querySelector('input[type=file]').click()"
              >
                更换头像
              </el-button>
            </el-upload>
          </div>
          
          <div class="user-stats">
            <div class="stat-item" v-for="stat in userStats" :key="stat.label">
              <el-icon class="stat-icon"><component :is="stat.icon" /></el-icon>
              <div class="stat-content">
                <span class="stat-label">{{ stat.label }}</span>
                <span class="stat-value">{{ stat.value }}</span>
              </div>
            </div>
          </div>
          
          <!-- 修改密码按钮 -->
          <div class="change-password-section">
            <el-button 
              type="primary" 
              class="change-password-btn"
              :icon="Lock"
              @click="openChangePasswordDialog"
            >
              修改密码
            </el-button>
          </div>
        </el-card>
      </el-col>
      
      <!-- 右侧表单区域 -->
      <el-col :span="24" :md="16">
        <el-card class="info-card">
          <template #header>
            <div class="card-header">
              <span>基本信息</span>
              <div class="header-actions">
                <el-button 
                  v-if="!isEditing" 
                  type="primary" 
                  @click="startEdit"
                  :icon="Edit"
                >
                  编辑信息
                </el-button>
                <div v-else class="edit-actions">
                  <el-button @click="cancelEdit">取消</el-button>
                  <el-button type="primary" @click="saveProfile" :loading="saving">保存</el-button>
                </div>
              </div>
            </div>
          </template>
          
          <el-form 
            :model="profileForm" 
            :rules="rules" 
            ref="profileFormRef" 
            label-position="left"
            label-width="80px"
            :disabled="!isEditing"
            class="profile-form"
          >
            <el-row :gutter="16">
              <el-col :span="12">
                <el-form-item label="账号" prop="username">
                  <el-input v-model="profileForm.username" disabled class="form-input short-input" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="nickname">
                  <template #label>
                    <span class="modified-marker" v-if="modifiedFields.nickname">*</span>
                    <span>昵称</span>
                  </template>
                  <el-input v-model="profileForm.nickname" :disabled="!isEditing" class="form-input short-input" />
                </el-form-item>
              </el-col>
            </el-row>
            
            <el-row :gutter="16">
              <el-col :span="12">
                <el-form-item prop="gender">
                  <template #label>
                    <span class="modified-marker" v-if="modifiedFields.gender">*</span>
                    <span>性别</span>
                  </template>
                  <el-select v-model="profileForm.gender" :disabled="!isEditing" placeholder="请选择性别" class="short-input">
                    <el-option label="男" value="男" />
                    <el-option label="女" value="女" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="age">
                  <template #label>
                    <span class="modified-marker" v-if="modifiedFields.age">*</span>
                    <span>年龄</span>
                  </template>
                  <el-input-number 
                    v-model="profileForm.age" 
                    :min="1" 
                    :max="120" 
                    :disabled="!isEditing"
                    controls-position="right"
                    class="form-input-number short-input"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            
            <el-row :gutter="16">
              <el-col :span="12">
                <el-form-item prop="driving_years">
                  <template #label>
                    <span class="modified-marker" v-if="modifiedFields.driving_years">*</span>
                    <span>驾龄</span>
                  </template>
                  <el-input-number 
                    v-model="profileForm.driving_years" 
                    :min="0" 
                    :max="80" 
                    :disabled="!isEditing"
                    controls-position="right"
                    class="form-input-number short-input"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="city">
                  <template #label>
                    <span class="modified-marker" v-if="modifiedFields.city">*</span>
                    <span>城市</span>
                  </template>
                  <el-input v-model="profileForm.city" :disabled="!isEditing" class="form-input short-input" />
                </el-form-item>
              </el-col>
            </el-row>
            
            <el-row :gutter="16">
              <el-col :span="12">
                <el-form-item prop="phone">
                  <template #label>
                    <span class="modified-marker" v-if="modifiedFields.phone">*</span>
                    <span>手机号</span>
                  </template>
                  <el-input v-model="profileForm.phone" :disabled="!isEditing" class="form-input short-input" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="email">
                  <template #label>
                    <span class="modified-marker" v-if="modifiedFields.email">*</span>
                    <span>邮箱</span>
                  </template>
                  <el-input v-model="profileForm.email" :disabled="!isEditing" class="form-input short-input" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
  </div>
  
  <!-- 修改密码对话框 -->
  <el-dialog
    v-model="changePasswordDialogVisible"
    title="修改密码"
    width="500px"
    :before-close="closeChangePasswordDialog"
  >
    <el-form 
      :model="passwordForm" 
      :rules="passwordRules" 
      ref="passwordFormRef" 
      label-width="100px"
    >
      <el-form-item label="原密码" prop="oldPassword">
        <el-input 
          v-model="passwordForm.oldPassword" 
          type="password" 
          show-password
          placeholder="请输入原密码"
          class="form-input short-input"
        />
      </el-form-item>
      
      <el-form-item label="新密码" prop="newPassword">
        <el-input 
          v-model="passwordForm.newPassword" 
          type="password" 
          show-password
          placeholder="请输入新密码"
          class="form-input short-input"
        />
      </el-form-item>
      
      <el-form-item label="确认新密码" prop="confirmPassword">
        <el-input 
          v-model="passwordForm.confirmPassword" 
          type="password" 
          show-password
          placeholder="请再次输入新密码"
          class="form-input short-input"
        />
      </el-form-item>
    </el-form>
    
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="closeChangePasswordDialog">取消</el-button>
        <el-button 
          type="primary" 
          @click="changePassword" 
          :loading="passwordSaving"
        >
          确认修改
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive, onMounted, watch, computed } from 'vue'
import { Edit, Plus, User, Male, Calendar, Timer, Location, Lock } from '@element-plus/icons-vue'
import { useUserStore } from '../store/user'
import { ElMessage, ElMessageBox } from 'element-plus'

const userStore = useUserStore()
const profileFormRef = ref()
const passwordFormRef = ref()
const isEditing = ref(false)
const saving = ref(false)
const passwordSaving = ref(false)
const avatarFile = ref(null)
const originalData = reactive({})
const modifiedFields = reactive({})
const changePasswordDialogVisible = ref(false)

// 表单数据
const profileForm = reactive({
  id: '',
  username: '',
  nickname: '',
  phone: '',
  email: '',
  avatar: '',
  gender: '',
  age: null,
  driving_years: null,
  city: ''
})

// 密码表单数据
const passwordForm = reactive({
  oldPassword: '',
  newPassword: '',
  confirmPassword: ''
})

// 计算用户统计信息
const userStats = computed(() => [
  { label: '性别', value: profileForm.gender || '未设置', icon: Male },
  { label: '年龄', value: profileForm.age || '未设置', icon: Calendar },
  { label: '驾龄', value: profileForm.driving_years !== null ? profileForm.driving_years + '年' : '未设置', icon: Timer },
  { label: '城市', value: profileForm.city || '未设置', icon: Location }
])

// 表单验证规则
const rules = {
  nickname: [
    { required: true, message: '请输入昵称', trigger: 'blur' }
  ],
  phone: [
    { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
  ],
  email: [
    { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
  ]
}

// 密码表单验证规则
const passwordRules = {
  oldPassword: [
    { required: true, message: '请输入原密码', trigger: 'blur' }
  ],
  newPassword: [
    { required: true, message: '请输入新密码', trigger: 'blur' },
    { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
  ],
  confirmPassword: [
    { required: true, message: '请确认新密码', trigger: 'blur' },
    { validator: validateConfirmPassword, trigger: 'blur' }
  ]
}

// 验证确认密码
function validateConfirmPassword(rule, value, callback) {
  if (value === '') {
    callback(new Error('请再次输入新密码'))
  } else if (value !== passwordForm.newPassword) {
    callback(new Error('两次输入的密码不一致'))
  } else {
    callback()
  }
}

// 打开修改密码对话框
const openChangePasswordDialog = () => {
  changePasswordDialogVisible.value = true
  // 清空密码表单
  passwordForm.oldPassword = ''
  passwordForm.newPassword = ''
  passwordForm.confirmPassword = ''
}

// 关闭修改密码对话框
const closeChangePasswordDialog = () => {
  changePasswordDialogVisible.value = false
}

// 初始化用户信息
const initProfile = () => {
  if (userStore.user) {
    Object.assign(profileForm, userStore.user)
    Object.assign(originalData, userStore.user)
    // 重置修改状态
    Object.keys(profileForm).forEach(key => {
      modifiedFields[key] = false
    })
  }
}

// 开始编辑
const startEdit = () => {
  isEditing.value = true
  // 监听表单变化
  Object.keys(profileForm).forEach(key => {
    watch(() => profileForm[key], (newVal) => {
      modifiedFields[key] = newVal !== originalData[key]
    })
  })
}

// 取消编辑
const cancelEdit = async () => {
  const hasChanges = Object.values(modifiedFields).some(v => v)
  if (hasChanges) {
    try {
      await ElMessageBox.confirm(
        '有未保存的修改，是否取消?',
        '提示',
        {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning'
        }
      )
      isEditing.value = false
      initProfile() // 恢复原始数据
    } catch {
      // 用户点击否，继续编辑
    }
  } else {
    isEditing.value = false
    initProfile() // 恢复原始数据
  }
}

// 处理头像上传
const handleAvatarChange = (file) => {
  const rawFile = file.raw
  if (rawFile) {
    // 验证文件类型
    const allowedTypes = ['image/jpeg', 'image/png', 'image/gif']
    if (!allowedTypes.includes(rawFile.type)) {
      ElMessage.error('头像必须是 JPG、PNG 或 GIF 格式!')
      return
    }
    
    // 验证文件大小 (最大2MB)
    if (rawFile.size > 2 * 1024 * 1024) {
      ElMessage.error('头像大小不能超过 2MB!')
      return
    }
    
    // 保存文件引用
    avatarFile.value = rawFile
    
    // 预览图片
    const reader = new FileReader()
    reader.onload = (e) => {
      profileForm.avatar = e.target.result
    }
    reader.readAsDataURL(rawFile)
  }
}

// 保存个人信息
const saveProfile = async () => {
  try {
    const valid = await profileFormRef.value.validate().catch(() => false)
    if (!valid) return
    
    saving.value = true
    
    // 准备要提交的数据
    const updateData = { ...profileForm }
    
    // 如果有新的头像文件，转换为Base64
    if (avatarFile.value) {
      const base64Data = await fileToBase64(avatarFile.value)
      updateData.avatar = base64Data
    }
    
    try {
      // 调用store更新用户信息
      const result = await userStore.updateProfile(updateData)
      
      if (result.success) {
        ElMessage.success('个人信息更新成功')
        isEditing.value = false
        avatarFile.value = null
        // 更新原始数据
        Object.assign(originalData, profileForm)
        // 重置修改状态
        Object.keys(modifiedFields).forEach(key => {
          modifiedFields[key] = false
        })
      } else {
        // 处理特定错误
        if (result.code === 409) {
          ElMessage.error(result.message || '手机号或邮箱已被使用')
        } else if (result.code === 401) {
          // 处理未授权错误，不跳转登录
          ElMessage.error('权限不足，请检查登录状态')
        } else {
          ElMessage.error(result.message || '更新失败，请重试')
        }
      }
    } catch (error) {
      console.error('保存失败:', error)
      // 捕获网络错误等异常
      ElMessage.error('保存失败: ' + (error.message || '网络错误'))
      // 保持编辑状态让用户可以重试
      isEditing.value = true
    }
  } catch (error) {
    console.error('保存失败:', error)
    ElMessage.error('保存失败: ' + (error.message || '服务器错误'))
  } finally {
    saving.value = false
  }
}

// 修改密码
const changePassword = async () => {
  try {
    const valid = await passwordFormRef.value.validate().catch(() => false)
    if (!valid) return
    
    // 检查原密码和新密码是否一致
    if (passwordForm.oldPassword === passwordForm.newPassword) {
      ElMessage.error('新密码不能与原密码一致')
      return
    }
    
    passwordSaving.value = true
    
    try {
      const result = await userStore.changePassword(
        passwordForm.oldPassword,
        passwordForm.newPassword
      )
      
      if (result.success) {
        ElMessage.success('密码修改成功')
        closeChangePasswordDialog()
      } else {
        ElMessage.error(result.message || '密码修改失败')
      }
    } catch (error) {
      console.error('修改密码失败:', error)
      ElMessage.error('修改密码失败: ' + (error.message || '服务器错误'))
    }
  } catch (error) {
    console.error('修改密码失败:', error)
    ElMessage.error('修改密码失败: ' + (error.message || '服务器错误'))
  } finally {
    passwordSaving.value = false
  }
}

// 将文件转换为Base64
const fileToBase64 = (file) => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.readAsDataURL(file)
    reader.onload = () => resolve(reader.result)
    reader.onerror = error => reject(error)
  })
}

// 页面加载时初始化用户信息
onMounted(() => {
  initProfile()
})
</script>

<style scoped>
/* 移除必填字段的红色星号 */
:deep(.el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label:before) {
  content: none;
}

.profile-container {
  padding: 24px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e7f4 100%);
  min-height: calc(100vh - 60px);
  backdrop-filter: blur(10px);
}

.info-card {
  margin-bottom: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: none;
  border-radius: 16px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  overflow: hidden;
}

.info-card:hover {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  font-weight: 600;
  padding: 20px 24px;
  color: #2c3e50;
  background: rgba(250, 250, 250, 0.8);
  margin: 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.header-actions {
  display: flex;
  gap: 12px;
}

.edit-actions {
  display: flex;
  gap: 8px;
}

.avatar-card {
  text-align: center;
}

.avatar-section {
  padding: 32px 0 24px;
}

.avatar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.avatar-container {
  position: relative;
  display: inline-block;
}

.avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.avatar-placeholder {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 4px solid #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.avatar-icon {
  font-size: 48px;
  color: white;
}

.user-nickname {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: #2c3e50;
  letter-spacing: 0.5px;
}

.user-username {
  margin: 4px 0 0;
  font-size: 14px;
  color: #7f8c8d;
}

.avatar-upload {
  margin-top: 16px;
}

.upload-btn {
  width: 120px;
  border-radius: 24px;
  background: linear-gradient(135deg, #409eff, #1a73e8);
  border: none;
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
  color: white;
  font-weight: 500;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
}

.upload-btn:hover {
  box-shadow: 0 6px 16px rgba(64, 158, 255, 0.4);
  transform: translateY(-2px);
}

.user-stats {
  padding: 0 24px 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  margin-top: 20px;
}

.stat-item {
  display: flex;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
}

.stat-item:last-child {
  border-bottom: none;
}

.stat-item:hover {
  background-color: rgba(64, 158, 255, 0.05);
  border-radius: 8px;
  padding-left: 12px;
  padding-right: 12px;
}

.stat-icon {
  font-size: 20px;
  color: #409eff;
  margin-right: 16px;
  width: 24px;
  height: 24px;
}

.stat-content {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-label {
  color: #7f8c8d;
  font-size: 14px;
  font-weight: 500;
}

.stat-value {
  color: #2c3e50;
  font-weight: 500;
  font-size: 15px;
}

.change-password-section {
  padding: 0 24px 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  margin-top: 20px;
}

.change-password-btn {
  width: 100%;
  border-radius: 10px;
  background: linear-gradient(135deg, #67c23a, #489c2d);
  border: none;
  box-shadow: 0 4px 12px rgba(103, 194, 58, 0.3);
  color: white;
  font-weight: 500;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
  height: 40px;
}

.change-password-btn:hover {
  box-shadow: 0 6px 16px rgba(103, 194, 58, 0.4);
  transform: translateY(-2px);
}

.profile-form {
  margin-top: 16px;
}

.form-input {
  max-width: 300px;
}

.form-input-number {
  max-width: 150px;
}

.short-input {
  max-width: 250px;
}

:deep(.el-card__body) {
  padding: 20px;
}

:deep(.el-form-item) {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
}

:deep(.el-form-item__label) {
  font-weight: 500;
  color: #2c3e50;
  font-size: 14px;
  letter-spacing: 0.3px;
  width: 80px;
  text-align: left;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

:deep(.el-form-item__label .modified-marker) {
  margin-right: 4px;
  color: #e6a23c;
  font-size: 12px;
}

:deep(.el-form-item__content) {
  flex: 1;
  margin-left: 20px !important;
}

:deep(.el-input__wrapper) {
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  background-color: #fff;
  border: 1px solid #e4e7ed;
  outline: none;
}

:deep(.el-input) {
  outline: none;
}

:deep(.el-input:focus) {
  outline: none;
  box-shadow: none;
}

:deep(.el-input__inner) {
  border: none;
  outline: none;
}

:deep(.el-input.is-focus) {
  outline: none;
  box-shadow: none;
}

:deep(.el-input__wrapper:hover) {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: #409eff;
}

:deep(.el-input--password .el-input__wrapper) {
  outline: none;
  box-shadow: none;
}

:deep(.el-input--password .el-input__wrapper:hover) {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: #409eff;
  outline: none;
}

:deep(.el-input--password .el-input__wrapper.is-focus) {
  outline: none;
  border-color: #409eff;
}

:deep(.el-input--password .el-input__wrapper:focus) {
  outline: none;
  box-shadow: none;
}

:deep(.el-input__wrapper.is-focus) {
  outline: none;
  border-color: #409eff;
}

/* 移除输入框焦点时的默认轮廓 */
:deep(.el-input__wrapper:focus) {
  outline: none;
  box-shadow: none;
}

:deep(.el-input__inner:focus) {
  outline: none;
  box-shadow: none;
}

:deep(.el-textarea__inner:focus) {
  outline: none;
  box-shadow: none;
}

/* 通用焦点样式重置 */
:deep(*:focus) {
  outline: none !important;
  box-shadow: none !important;
}

:deep(.el-select) {
  width: 100%;
  max-width: 250px;
}

:deep(.el-select .el-input__wrapper:focus) {
  outline: none;
  box-shadow: none;
}

:deep(.el-select .el-input__inner:focus) {
  outline: none;
  box-shadow: none;
}

:deep(.el-button) {
  border-radius: 8px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 500;
  letter-spacing: 0.5px;
}

:deep(.el-button:hover) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

:deep(.el-button--primary) {
  background: linear-gradient(135deg, #409eff, #1a73e8);
  border: none;
}

:deep(.el-button--primary:hover) {
  background: linear-gradient(135deg, #1a73e8, #409eff);
  box-shadow: 0 6px 16px rgba(64, 158, 255, 0.4);
}

:deep(.el-input-number .el-input__wrapper) {
  box-shadow: none;
  border: 1px solid #dcdfe6;
}

:deep(.el-input-number .el-input__wrapper:hover) {
  box-shadow: none;
  border-color: #409eff;
}

:deep(.el-input-number .el-input__wrapper.is-focus) {
  box-shadow: 0 0 0 1px #409eff inset;
  border-color: #409eff;
  outline: none;
}

:deep(.el-input-number .el-input__inner:focus) {
  outline: none;
  box-shadow: none;
}

:deep(.el-input-number .el-input__wrapper:focus) {
  outline: none;
  box-shadow: none;
}

/* 对话框样式 */
:deep(.el-dialog) {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

:deep(.el-dialog__header) {
  background: rgba(250, 250, 250, 0.8);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  padding: 20px 24px;
  margin-right: 0;
}

:deep(.el-dialog__title) {
  font-size: 20px;
  font-weight: 600;
  color: #2c3e50;
}

:deep(.el-dialog__body) {
  padding: 24px;
}

:deep(.el-dialog__footer) {
  padding: 16px 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  background: rgba(250, 250, 250, 0.5);
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .profile-container {
    padding: 16px;
  }
  
  :deep(.el-card__body) {
    padding: 20px 16px;
  }
  
  .avatar {
    width: 100px;
    height: 100px;
  }
  
  .avatar-placeholder {
    width: 100px;
    height: 100px;
  }
  
  .avatar-icon {
    font-size: 36px;
  }
  
  .user-nickname {
    font-size: 20px;
  }
  
  .stat-item {
    padding: 12px 0;
  }
  
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    font-size: 18px;
  }
  
  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }
  
  .stat-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  
  .stat-value {
    font-size: 14px;
  }
  
  :deep(.el-form-item__label) {
    font-size: 13px;
  }
  
  :deep(.el-dialog) {
    width: 90% !important;
  }
  
  .form-input,
  .form-input-number,
  .short-input {
    max-width: 100%;
  }
  
  :deep(.el-select) {
    max-width: 100%;
  }
  
  :deep(.el-form-item) {
    margin-bottom: 16px;
    flex-direction: column;
    align-items: flex-start;
  }
  
  :deep(.el-form-item__content) {
    margin-left: 0 !important;
    width: 100%;
    margin-top: 8px;
  }
}
</style>